/* eslint-disable camelcase,standard/no-callback-literal */
export default {
  login (session_id, session_vc, cb) {
    if (this.isLoggedIn()) {
      if (cb) cb(true)
      this.onChange(true)
      return
    }
    if (!!session_id && !!session_vc) {
      sessionStorage.session_id = session_id
      sessionStorage.session_vc = session_vc
      if (cb) cb(true)
      this.onChange(true)
    } else {
      if (cb) cb(false)
      this.onChange(false)
    }
  },

  getSession_id () {
    return sessionStorage.session_id ? sessionStorage.session_id : 0
  },

  getSession_vc () {
    return sessionStorage.session_vc ? sessionStorage.session_vc : 0
  },

  logout (cb) {
    delete sessionStorage.session_id
    delete sessionStorage.session_vc
    if (cb) cb()
    this.onChange(false)
  },

  isLoggedIn () {
    return !!sessionStorage.session_id && !!sessionStorage.session_vc
  },

  onChange () {}
}
